using System.Linq.Expressions;

namespace S.M.SmartMedical.Infrastructure.BaseRepository
{
    /// <summary>
    /// 通用仓储接口
    /// 提供基础的CRUD操作方法
    /// </summary>
    /// <typeparam name="T">实体类型</typeparam>
    public interface IRepository<T> where T : class
    {
        /// <summary>
        /// 获取所有实体
        /// </summary>
        /// <returns>实体集合</returns>
        IQueryable<T> GetAllAsync();

        /// <summary>
        /// 获取可查询的实体集合
        /// </summary>
        /// <returns>可查询的实体集合</returns>
        IQueryable<T> GetQueryable();

        /// <summary>
        /// 根据ID获取单个实体
        /// </summary>
        /// <param name="id">实体ID</param>
        /// <returns>实体对象</returns>
        Task<T?> GetByIdAsync(object id);

        /// <summary>
        /// 根据条件获取单个实体
        /// </summary>
        /// <param name="predicate">查询条件</param>
        /// <returns>实体对象</returns>
        Task<T?> GetAsync(Expression<Func<T, bool>> predicate);

        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">要添加的实体</param>
        /// <returns>添加后的实体</returns>
        Task<int> AddAsync(T entity);

        /// <summary>
        /// 批量添加实体
        /// </summary>
        /// <param name="entities">要添加的实体集合</param>
        /// <returns>添加的实体数量</returns>
        Task<int> AddRangeAsync(IEnumerable<T> entities);

        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="entity">要更新的实体</param>
        /// <returns>更新后的实体</returns>
        Task<int> UpdateAsync(T entity);
    }
}
